var { Plot } = require("../../Plot.js")
var { Point } = require("../../Point")

function randInit(n) {
	var list = new Array(n)
	for (var i = 0; i < n; i++) {
		list[i] = { x: 20 * Math.random(), y: 20 * Math.random() }
	}
	return list;
}

function norma(list) {
	var s = 0;
	list.forEach(v => {
		s += v.wg
	})
	list.forEach(v => {
		v.wg = v.wg / s
	})
}

// var list = randInit(5)
var list = [{ "x": 1.4452629752150914, "y": 8.183094219902731 },
{ "x": 10.161795549342404, "y": 10.885232407334895 },
{ "x": 6.893246932790911, "y": 6.997898919423564 },
{ "x": 11.505516943733811, "y": 12.71185733733143 },
{ "x": 13.8500964707268, "y": 10.57130236767238 }]
console.log(JSON.stringify(list))
console.log(list)
var ct = Point.countCenter(list)

list.forEach((v, idx) => {
	v.wg = 1 / Point.len(v, ct)
	v.name = idx + '.x'
})

list.sort((v, v1) => {
	return v.wg < v1.wg ? 1 : -1
})
console.table(list)

for (var t = 0; t < 222; t++) {
	var newwg = []
	list.forEach((v, idx) => {
		var sumwg = 0
		for (let index = 0, len = list.length; index < len; index++) {
			if (idx == index)
				continue
			const element = list[index];

			sumwg += list[index].wg / Point.len(element, v)
		}
		// v.wg = sumwg
		newwg[idx] = sumwg
		// v.wg = Point.len(v, ct)
	})

	list.forEach((v, idx) => {
		v.wg = newwg[idx]
	})

	if (t % 6 == 0) {
		norma(list)
		console.table(list)
	}
}
norma(list)
list.sort((v, v1) => {
	return v.wg < v1.wg ? 1 : -1
})
console.table(list)

// S:\源码\Geometry\Point.js

// var plot = new Plot(document.getElementById("myCanvas"));
// var md = require("./points123")


// plot.drawList  //(md.list)
// global.plot = plot